
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>礼物</title>
    <link rel="stylesheet" href="/${BasePath}/static/css/weui.css" media="all" />
    <link rel="stylesheet" href="/${BasePath}/static/css/layer.css" media="all" />
    <link rel="stylesheet" href="/${BasePath}/static/css/font-awesome.min.css" media="all" />
    <style type="text/css">
    	 * {
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }
        html{width:100%;height:100%}
        body{background: url('/${BasePath}/static/images/pay_bg.png') top center no-repeat; background-size:100%;width:100%;height:100%;padding:40px}
        .gift{width:100%;height:90%;background:#fff;border-radius: 8px;overflow:auto;padding:30px}
        .gift .item{float:left;width:50%;text-align:center;margin-bottom:40px}
        .gift .item img{display:block;width:295px;height:200px}
        .gift .item p{font-size: 30px;line-height: 46px;padding-bottom: 10px;}
        .info{text-align: center;font-size: 24px;color: #000;}
        .info1{margin-top:15px}
        .gift .item a{display:block;font-size: 30px;width: 138px;height: 50px;line-height:50px;margin:0 auto;background: white;border-radius: 6px;color: #00bc0c;border: 1px solid #00bc0c;}
    </style>
</head>
<body ontouchstart>
	<div id="app" class="gift">
	    <input type="hidden" id="activityid" value="${activityid!''}">
	    <input type="hidden" id="playerid" value="${playerid!''}">
	    <#list vglist as giftall>
		    <div class="item">
		    	<img src="${giftall.giftpic}">
		    	<p>${giftall.price}点=${giftall.votenum}赞</p>
		    	<a onclick="pay(${giftall.id!''})">赠送</a>
		    </div>
	    </#list>
	</div>
	<div class="info info1">活动重在参与，意在宣传活动，</div>
	<div class="info">不提倡购买，一经购买，不予退款</div>
    <script type="text/javascript" src="/${BasePath}/static/js/zepto.min.js"></script>
    <script type="text/javascript" src="/${BasePath}/static/js/layer.js"></script>
    <script type="text/javascript" src="/${BasePath}/static/js/vue.min.js"></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common.js"></script>
    <script type="text/javascript" src="/${BasePath}/static/js/axios.min.js"></script>
    <script type="text/javascript">
    	//设置meta
	    var kuan=window.screen.width;
	    var she=750;
	    var chu=kuan/she;
	    var meta=document.createElement('meta');
	    meta.name='viewport';
	    meta.content='width=750px,user-scalable=no,initial-scale='+chu+',minimum-scale='+chu+',maximum-scale='+chu+'';
	    document.head.appendChild(meta);
	    function getUrlParam(b) {
	        var c = new RegExp("(^|&)" + b + "=([^&]*)(&|$)","i");
	        var a = window.location.search.substr(1).match(c);
	        if (a != null && a[2] != "null") {
	            return decodeURIComponent(a[2])
	        }
	        return null
	    }
	    var activityid = getUrlParam('activityid');
	    var playerid = getUrlParam('playerid');
	    var arr = "";
	    console.log(activityid);
	    function pay(num){
	    	layer.open({
	    	    type: 2
	    	    ,content: '加载中'
	    	});
	    	axios.get('/${BasePath}/pay/createOrder',{
	    		params:{
	    			activityid: $("#activityid").val(),
	    			playerid: $("#playerid").val(),
	    			vgiftid: num,
	    			openid: openid
	    		}
	    	})
	    	.then(function(response){
	    		layer.closeAll();
	    		console.log(response.data);
	    		var onBridgeReady =function(){
	    			WeixinJSBridge.invoke(
			    			'getBrandWCPayRequest', {
			    			     "appId":response.data.appId,     //公众号名称，由商户传入     
			    			     "timeStamp":response.data.timeStamp,         //时间戳，自1970年以来的秒数     
			    			     "nonceStr":response.data.nonceStr, //随机串     
			    			     "package":response.data.package,     
			    			     "signType":response.data.signType,         //微信签名方式：     
			    			     "paySign":response.data.paySign //微信签名 
			    			},
			    			function(res){	
			    				if (res.err_msg == "get_brand_wcpay_request:ok") {
			    			    	layer.open({
    								    content: "支付成功"
    								    ,skin: 'msg'
    								    ,time: 2 
    								});
			    			    	setTimeout(function(){
			    			    		window.location.href="/${BasePath}/free/toPlayerDetail?playerid=" + playerid + '&activityid=' + activityid;
			                    	},2000)
			    			    }
			    			    else if (res.err_msg == "get_brand_wcpay_request:cancel") {
			    			    	layer.open({
    								    content: "您取消支付"
    								    ,skin: 'msg'
    								    ,time: 2 
    								});
			    			    }
			    			    else {
			    			    	layer.open({
    								    content: "支付失败"
    								    ,skin: 'msg'
    								    ,time: 2 
    								});
			    			    }
			    	  		}
			    		); 
	    		}
	    		if (typeof WeixinJSBridge == "undefined"){
		    		if( document.addEventListener ){
		    		   document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
		    		}else if (document.attachEvent){
		    		   document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
		    		   document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
		    		}
		    		}else{
		    			onBridgeReady()
		    		}
	    		
	    	})
	    	.catch(function(error){
	    		console.log(error);
	    	})
	    }
    </script>
</body>
</html>
